/**
 * @file pwm.c
 * @brief T1 PWM Driver
 *
 * @author yemt@witsi.cn
 * @date 2012-04-10
 * @version T1.PWM.01
 */
#include "regs.h"
#include "dev.h"
#include "pwm.h"
#include "config.h"

void pwm_init(int n, uint32_t clock, uint32_t duty)
{
        uint32_t tmp = CONFIG_PCLK0 / clock;
        clock = tmp * duty / 100;
        PWM->PWM_REG[n] = (clock << 16) | (tmp - clock);
}

void pwm_start(int n)
{
        PWM->PWM_CTL |= (1 << n);
        return;
}

void pwm_stop(int n)
{
        PWM->PWM_CTL &= ~(1 << n);
        return;
}
